package cn.laixueit.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CorsConfig {

    @Bean
    public CorsFilter corsFilter(){
        // 1 添加cors配置信息
        CorsConfiguration config = new CorsConfiguration();
        // 1.1 允许的域
        config.addAllowedOrigin("http://manage.chuangmei.com");
        config.addAllowedOrigin("http://www.chuangmei.com");
        // 1.2 允许的cookie
        config.setAllowCredentials(true);
        // 1.3 允许的请求方法
        config.addAllowedMethod("*");
        // 1.4 允许的头信息
        config.addAllowedHeader("*");


        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**",config);

        return new CorsFilter(source);
    }
}
